package com.jdk.demo.nio.bytebuffer;

import java.nio.ByteBuffer;

public class WrapDemo {

	public static void main(String[] args) {
		byte[] byteArray = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
		ByteBuffer byteBuffer1 = ByteBuffer.wrap(byteArray); // hb: [1, 2, 3, 4, 5, 6, 7, 8]
		ByteBuffer byteBuffer2 = ByteBuffer.wrap(byteArray, 2, 4); // hb: [1, 2, 3, 4, 5, 6, 7, 8], position=offset, limit=offset+length, capacity=byteArray.length
		System.out.println("byteBuffer1 capacity=" + byteBuffer1.capacity() + ", position=" + byteBuffer1.position() + " limit=" + byteBuffer1.limit());
		System.out.println("byteBuffer2 capacity=" + byteBuffer2.capacity() + ", position=" + byteBuffer2.position() + " limit=" + byteBuffer2.limit());
	}

}
